<template>
  <div class="full">
    <el-scrollbar>
      <div class="dlText-120 list-b-12 p-12">
        <PackageInfo :data="data.baseData" :isEdit="isEdit" />
        <el-divider />
        <el-affix position="bottom" :offset="60" v-if="isEdit">
          <div class="flex-center-center">
            <el-button type="primary" @click="saveBtn(data.baseData)">保存包装信息</el-button>
          </div>
        </el-affix>
      </div>
    </el-scrollbar>
  </div>
</template>
<script setup lang="ts">
import '../pageCss.scss'; // 引入样式
const { proxy } = getCurrentInstance() as any;
const props = withDefaults(
  defineProps<{
    data?: any;//数据源
    isEdit?: boolean;//是否編輯
    options?: any;//数据组
    setState?: Function;//更改状态
    isText?: boolean;//是否仅文本
  }>(),
  {
  },
);
const emit = defineEmits<{
  //fn为父组件引入子组件是定义的子组件事件属性，可随意定义
  (event: 'saveBtn'): void;
}>();
const saveBtn = (form: any) => {
  if (!!!form.productName) {
    proxy.$message('产品名称不能为空', 'error')
    return
  }
  Promise.all([
    UpdateProductPackage(),//修改包装信息
  ]).then((res: any) => {
    if (props.setState && typeof props.setState === 'function') {
      props.setState(5, '保存成功')
    }
  }).catch(() => {

  });
};
//修改包装信息
const UpdateProductPackage = () => {
  return new Promise((resolve, reject) => {
    proxy.$api.OrderBusniess.UpdateProductPackage(props.data.baseData)
      .then((res: any) => {
        resolve(res)
      })
      .catch((e: any) => {
        reject(e)
      });
  });
};
onMounted(() => {
});
</script>
